package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IBookReserveService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.BookReserveReqVO;
import com.bjc.base.bean.response.BookReserveVO;

/**
 * <p>
 * 绘本预订 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "bookReserve-api", tags = { "绘本预订相关接口" })
public class BookReserveController {

    @Autowired
    private IBookReserveService bookReserveService;

	@ApiOperation("分页查询绘本预订")
	@GetMapping("bookReserve/findPage")
	public ResultVO getBookReservePage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			BookReserveReqVO bookReserveReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<BookReserveVO> bookReserveVOs = bookReserveService.getList(bookReserveReqVO);
		return ResultGenerator.getSuccess(new PageInfo<BookReserveVO>(bookReserveVOs));
	}
	
	@ApiOperation("分页查询绘本预订")
	@GetMapping("bookReserve/find")
	public ResultVO getBookReservee(BookReserveReqVO bookReserveReqVO) {
		BookReserveVO bookReserveVO = bookReserveService.get(bookReserveReqVO);
		return ResultGenerator.getSuccess(bookReserveVO);
	}

	@ApiOperation("添加绘本预订")
	@PostMapping("bookReserve/create")
	public ResultVO createBookReserve(@RequestBody BookReserveReqVO bookReserveReqVOs) {
		int count = bookReserveService.insert(bookReserveReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新绘本预订")
	@PutMapping("bookReserve/update")
	public ResultVO updateBookReserve(@RequestBody BookReserveReqVO bookReserveReqVOs) {
		int count = bookReserveService.update(bookReserveReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除绘本预订")
	@DeleteMapping("bookReserve/deleteList")
	public ResultVO deleteBookReserve(@ApiParam(value = "bookReserve id集合") @RequestBody int[] ids) {
		int count = bookReserveService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
